from typing import List, Dict


def transform_data(data: List[Dict]) -> List[Dict]:
    """Преобразование данных."""
    result = []

    time_intervals = {"morning": [], "evening": [], "night": []}

    sorted_data = sorted(data, key=lambda x: (x.date, x.shift))

    current_date = None
    current_week = None
    current_weekday = None

    for entry in sorted_data:
        date = entry.date
        week = entry.week
        weekday = entry.weekday
        shift = entry.shift

        if current_date != date or current_week != week or current_weekday != weekday:
            if current_date is not None:
                result.append(
                    {
                        "date": current_date,
                        "week": current_week,
                        "weekday": current_weekday,
                        **time_intervals,
                    }
                )

            current_date = date
            current_week = week
            current_weekday = weekday
            time_intervals = {"morning": [], "evening": [], "night": []}

        if shift == "Утро":
            time_intervals["morning"].append(entry.name)
        elif shift == "Вечер":
            time_intervals["evening"].append(entry.name)
        else:
            time_intervals["night"].append(entry.name)

    if current_date is not None:
        result.append(
            {
                "date": current_date,
                "week": current_week,
                "weekday": current_weekday,
                **time_intervals,
            }
        )
    return result
